<?php

class Leaf{
    
    private $parent;
    private $value;
    private $id;
    private $childs;    
    
    public function __construct($id,$value = null) {
        $this->id = $id;
        if ($value != null){
            $this->value = $value;
        }
    }
    
    public function setParent($parent){
        $this->parent = $parent;
    }
    
    public function setValue($value){
        $this->value = $value;
    }
    
    public function setChilds($childs){
        $this->childs = $child;
    }
    
    public function getParent(){
       return $this->parent;
    }
    
    public function getValue(){
       return $this->value; 
    }
    
    public function getId(){
       return $this->id; 
    }
    
    public function getChilds(){
       return $this->childs; 
    }
    /**
     * returns "not found" if not found
     * 
     * @param type $id
     * @return Leaf 
     */
    public function getChild($id){
        if ($this->id == $id){
            return $this;
        }            
        foreach ($this->childs as $key) {                        
            $ret = $key->getChild($id);
            if($ret->id == $id){
                return $ret;
            }
        }
        return "not found";
    }

    public function getLastChild(){
        return $this->childs[count($this->childs)];
    }
    
    public function addChild($leaf){
        $this->childs[count($this->childs)] = $leaf;
    }
    
}
 
?>
